package com.demo.controller;

import com.demo.aop.AuthorizationRequired;
import com.demo.core.constants.HttpStatus;
import com.demo.core.domain.Result;
import com.demo.core.exception.ParameterException;
import com.demo.domain.vo.MyTeamView;
import com.demo.service.MyTeamViewService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/myTeam")
public class MyTeamViewController {
    @Autowired
    private MyTeamViewService myTeamViewService;

    //    返回队伍管理页面所有数据
    @AuthorizationRequired
    @Operation(summary = "获取‘我的队伍’页面的所有信息")
    @RequestMapping("/getAllTeamMessagesByUid")
    public Result getAllTeamMessagesByUid(HttpServletRequest request) throws ParameterException {
        if (request == null) {
            throw new ParameterException("request为空");
        }
        Long uid = (Long) request.getAttribute("userId");
        List<MyTeamView> list = myTeamViewService.getAllTeamsInfoByUid(uid);
        return list == null || list.size() == 0 ?
                Result.success(HttpStatus.SUCCESS, "未查找到该用户的队伍信息", new ArrayList()) :
                Result.success(HttpStatus.SUCCESS, "队伍信息查找成功", list);
    }
}
